package com.mf.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.config.GlobalParameter;
import com.mf.controller.CodeController;
import com.mf.entity.Workday;
import com.mf.mapper.TapePurchaseHistoryMapper;
import com.mf.mapper.TapePurchaseMapper;
import com.mf.service.ITapePurchaseHistoryService;
import com.mf.service.IWorkdayService;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.Date;

/**
 * ClassName: CodeTask
 * Package: com.mf.task
 * Description: 股票更新
 *
 * @Author: lmf
 * @Create: 2024/5/24 11:24
 * @Version: 1.0
 */
@Component
public class CodeTask {

    @Resource
    private IWorkdayService workdayService;

    @Resource
    private CodeController codeController;

    /**
     * 每天4点更新当天股票数据
     * 0 0 16 * * ?
     */
    @Scheduled(cron = "0 0 16 * * ?")
    public void getCodeDailyData(){

        String date = LocalDate.now().format(GlobalParameter.FORMATTER2);
        LambdaQueryWrapper<Workday> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Workday::getDate, date);
        Workday one = workdayService.getOne(queryWrapper);

        if (one != null) {
            // 暂时直接调用 controller 里面的方法 后续在去修改
            codeController.addNewestCode();
        }
    }
}
